/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Model.Constants;
import Controller.SampleTranfer;
import Model.Position;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author PhucAnh
 */
public class BoardInterface extends javax.swing.JFrame {

    private int move;
    private JButton[][] arrayOfButton = new JButton[20][20];
    private javax.swing.JPanel gamePanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel player1Label;
    private javax.swing.JLabel player2Label;
    private javax.swing.JLabel scoreOfPlayer1;
    private javax.swing.JLabel scoreOfPlayer2;
    private javax.swing.JLabel player1Icon;
    private javax.swing.JLabel player2Icon;
    private javax.swing.JLabel moveLabel;
    private javax.swing.JLabel totalScoreLabel;
    private javax.swing.JLabel turnLabel;
    private javax.swing.JLabel timeLabel;
    private javax.swing.JLabel totalMoveLabel;
    private javax.swing.JButton newGameButton;
    private javax.swing.JPanel titlePanel;
    private JButton backButton;
    private JButton undoButton;
    private int score1 = 0;
    private int score2 = 0;
    private JProgressBar progressBar;
   

    public BoardInterface() {
        initComponents();
        setSize(900, 750);
        setResizable(true);
        setVisible(true);

    }

    public static void main(String[] args){
    	new BoardInterface();
    }

    private void initComponents() {
        setTitle("");
        jButton1 = new javax.swing.JButton();
        titlePanel = new javax.swing.JPanel();
        player1Label = new javax.swing.JLabel();
        player2Label = new javax.swing.JLabel();
        scoreOfPlayer1 = new javax.swing.JLabel();
        scoreOfPlayer2 = new javax.swing.JLabel();
        player1Icon = new javax.swing.JLabel();
        player2Icon = new javax.swing.JLabel();
        moveLabel = new javax.swing.JLabel();
        totalScoreLabel = new javax.swing.JLabel();
        turnLabel = new javax.swing.JLabel();
        timeLabel = new javax.swing.JLabel();
        totalMoveLabel = new javax.swing.JLabel();
        newGameButton = new javax.swing.JButton();
        gamePanel = new javax.swing.JPanel();
        undoButton = new JButton();
        backButton = new JButton();
        progressBar = new JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        player1Label.setText("null");

        player2Label.setText("null");

        scoreOfPlayer1.setText(String.valueOf(0));

        scoreOfPlayer2.setText(String.valueOf(0));

        player1Icon.setIcon(null);

        player2Icon.setIcon(null);

        moveLabel.setText("Turn: ");

        totalScoreLabel.setText("Total Score");

        turnLabel.setText("Turn ");
        backButton.setText("Menu");
        undoButton.setText("Undo");
        totalMoveLabel.setText(" move : ");
        newGameButton.setText("New game");

       
        titlePanel = new JPanel(new GridLayout(3, 5,10,10));
        titlePanel.add(new JLabel());
        titlePanel.add(new JLabel("Score"));
        titlePanel.add(new JLabel("Turn"));
        titlePanel.add(new JLabel("     total Move: "));    
        titlePanel.add(undoButton);
        titlePanel.add(player1Label);
        titlePanel.add(scoreOfPlayer1);
        titlePanel.add(player1Icon);
        titlePanel.add(new JLabel());
        titlePanel.add(backButton);
        titlePanel.add(player2Label);          
        titlePanel.add(scoreOfPlayer2);
        titlePanel.add(player2Icon);
        titlePanel.add(progressBar);
        titlePanel.add(newGameButton);
        titlePanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        

        arrayOfButton = new JButton[20][20];
        gamePanel = new JPanel();
        gamePanel.setLayout(new GridLayout(20, 20));
        for (int i = 0; i < 20; i++) {
            for (int j = 0; j < 20; j++) {
                arrayOfButton[i][j] = new JButton();
                arrayOfButton[i][j].setBackground(Color.WHITE);
                gamePanel.add(arrayOfButton[i][j]);

            }
        }
        setLayout(new BorderLayout());
        try {
			add(new ChatZonePanel(),BorderLayout.EAST);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        add(titlePanel, BorderLayout.NORTH);
        add(gamePanel, BorderLayout.CENTER);
        add(new JLabel("NÆ°á»›c Ä‘i: "), BorderLayout.SOUTH);

    }

    public void addCellListener(ActionListener al) {
        for (int i = 0; i < 20; i++) {
            for (int j = 0; j < 20; j++) {
                arrayOfButton[i][j].addActionListener(al);
            }
        }
            newGameButton.addActionListener(al);
    }

    public void setPlayer1Name(String name) {
        player1Label.setText(name);
    }

    public void setPlayer2Name(String name) {
        player2Label.setText(name);
    }

    public JButton getjButton1() {
        return jButton1;
    }

    public void setPlayer1Icon(ImageIcon ico) {
        this.player1Icon.setIcon(ico);
    }

    public void setPlayer2Icon(ImageIcon ico) {
        this.player2Icon.setIcon(ico);
    }

    public void setjButton1(JButton jButton1) {
        this.jButton1 = jButton1;
    }

    public JButton getArrayOfButton(int x, int y) {
        return arrayOfButton[x][y];
    }

    public void setArrayOfButton(int x, int y, Icon ico) {
        arrayOfButton[x][y].setIcon(ico);
    }
    public void setArrayOfButton(Position pos, Icon ico) {
        arrayOfButton[pos.getX()][pos.getY()].setIcon(ico);
    }

    public JLabel getTotalMoveLabel() {
        return totalMoveLabel;
    }

    public void setTotalMoveLabel(String text) {
        this.totalMoveLabel.setText(text);
    }

    public int getPlayer1Score() {
        return Integer.parseInt(scoreOfPlayer1.getText());
    }

    public int getPlayer2Score() {
        return Integer.parseInt(scoreOfPlayer1.getText());
    }

    public void setPlayer1Score(int score) {
        this.scoreOfPlayer1.setText(String.valueOf(score));
    }

    public void setPlaye2Score(int score) {
        this.scoreOfPlayer2.setText(String.valueOf(score));
    }

    public JButton getNewGameButton() {
        return newGameButton;
    }

    public JLabel getMoveLabel() {
        return moveLabel;
    }

    public JLabel getTimeLabel() {
        return timeLabel;
    }

    public void setDefaultBoard() {
        for (int i = 0; i < 20; i++) {
            for (int j = 0; j < 20; j++) {
                arrayOfButton[i][j].setIcon(null);
            }
        }
    }
   public static void main(){
	   new BoardInterface();
	   
   }
}
